//派发器

//导入逻辑
import todoReducer from '../reducers/todoList';
import {
  ADD,
  REMOVE,
  COMPLETED
} from '../actions/todoList';

export default (ctx) => {
  // console.log(ctx.$data);
  // console.log(ctx);
  //VueComponent{...}

  const {
    addItem,
    removeItem,
    changeCompleted
  } = todoReducer(ctx.todoData);

  return function (type, arg) {
    switch (type) {
      case ADD:
        // console.log(arg);
        //{id: 1637677651046, text: '123', completed: false}

        // console.log(addItem(arg));
        //[{…}]

        ctx.todoData = addItem(arg);
        // console.log(ctx.todoData);
        //[{…}]
        break;

      case REMOVE:
        ctx.todoData = removeItem(arg);
        break;

      case COMPLETED:
        ctx.todoData.completed = changeCompleted(arg);
        break;

      default:
        break;
    }
  }
}